package cn.itsource.ymjs.fallback;

import cn.itsource.ymjs.api.CourseDocAPI;
import cn.itsource.ymjs.doc.CourseDoc;
import cn.itsource.ymjs.util.AjaxResult;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 注要交给spring管理
 * @program: hrm-parent
 * @author: Mr.Zhang
 * @create: 2022-01-10 00:18
 **/
@Component
public class CourseDocFallBackFactory implements FallbackFactory<CourseDocAPI> {

    /**
     * 打印日志
     */
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public CourseDocAPI create(Throwable throwable) {
        return new CourseDocAPI() {
            @Override
            public AjaxResult batchAdd(List<CourseDoc> docs) {
                // 打印异常
                throwable.printStackTrace();
                logger.error("批量添加失败！系统异常，请联系管理员");
                // 返回熔断回调信息
                return AjaxResult.me().setSuccess(false).setMessage("批量添加失败！系统异常，请联系管理员");
            }

            @Override
            public AjaxResult batchDel(List<Long> ids) {
                throwable.printStackTrace();
                logger.error("批量添加失败！{}",ids);
                return AjaxResult.me().setSuccess(false).setMessage("批量删除失败！系统异常，请联系管理员");
            }
        };
    }
}
